﻿package com.h819.core.file;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

;

public class TxTUtils {

	/**
	 * 直接应用原始的FileUtils中的方法，不要自己编写类了
	 * 
	 * 直接应用 org.apache.commons.io.FileUtils 中的方法，未做改动
	 * Reads the contents of a file line by line to a List of Strings.
	 * 
	 * @param file
	 * @param encoding
	 * @return
	 */

	public static List<String> readLines(File file, String encoding) {

		try {
			List<String> readLines = FileUtils.readLines(file, encoding);
			List<String> temp = new ArrayList<String>();
			
			for(String s : readLines)
				if(StringUtils.contains(s, "Deur 3 ")||StringUtils.contains(s, "Deur 4 "))
					temp.add(s);
		
			return temp;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 直接应用 org.apache.commons.io.FileUtils 中的方法，未做改动
	 *  Writes the toString() value of each item in a collection to the specified File line by line.
	 * @param file
	 * @param lines
	 */
	public static void writeLines(File outPutFile) {
				
		try {
			FileUtils.writeLines(outPutFile, readLines(new File("E:\\Titan\\2008-10-15.txt"), "GBK"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
   

	public static void main(String[] args) {

		TxTUtils tu = new TxTUtils();
		int count =0;

		//		for (Iterator<String> it=tu.readLines(new File("D:\\TXT\\jb.txt"), "GBK").iterator(); it.hasNext(); ) {
		//	        Object element = it.next();
		//	    }

//		for (String line : tu.readLines(new File("D:\\TXT\\jb.txt"), "GBK"))
//		{
//			count ++;
//			System.out.println(line);
//			
//		}
//		System.out.println("count is :" +count);
		//System.out.println(tu.readLines(new File("D:\\TXT\\jb.txt"), "GBK"));
		
		TxTUtils.writeLines(new File("E:\\Titan\\2008-10-27_door3.txt"));
	}

}
